﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class SkinPanelManage : MonoBehaviour
{

    public GameObject content;
    /// <summary>
    /// 皮肤界面的toggleGroup组件
    /// </summary>
    //public ToggleGroup toggleGroup;
    public Animator animator;

    /// <summary>
    /// 当前皮肤栏拥有的皮肤列表
    /// </summary>
    public List<Transform> skinsOfSelf;
    /// <summary>
    /// 当前被选中的皮肤
    /// </summary>
    public CharacterInfo skinOnSwitch;


    /// <summary>
    /// 切换皮肤栏
    /// </summary>
    /// <param name="toggle"></param>
    public void Toggle_For_TurnChoice(Toggle toggle)
    {
        if (toggle.isOn)
        {
            content.SetActive(true);

            //找出当前皮肤栏中被选中的皮肤
            int length = skinsOfSelf.Count;
            Toggle curToggle;
            for (int i = 0; i < length; i++)
            {
                curToggle = skinsOfSelf[i].GetComponentInChildren<Toggle>();

                if (curToggle.isOn)
                {
                    skinOnSwitch = skinsOfSelf[i].GetComponent<CharacterInfo>();
                    User.instance.skinOnSwitch = skinOnSwitch;
                    animator.runtimeAnimatorController = User.instance.skinOnSwitch.anim;
                    User.instance.skinOnSwitch.isSwitch = true;
                    //Debug.Log(curToggle.transform.parent.name);
                    return;
                }
            }

            //IEnumerable<Toggle> toggles = toggleGroup.ActiveToggles();
            //Toggle curToggle = toggles.GetEnumerator().Current;
            //if (curToggle == null)
            //{
            //    Debug.Log("null");
            //    return;
            //}
            //animator.runtimeAnimatorController = curToggle.transform.parent.GetComponent<CharacterInfo>().anim;
        }
        else
        {
            content.SetActive(false);
            if (skinOnSwitch)
            {
                skinOnSwitch.isSwitch = false;
                //Debug.Log(skinOnSwitch.name + "——isSwitch = false");
            }
        }
    }

    /// <summary>
    /// 皮肤界面的开始按键
    /// </summary>
    public void Button_StartGame()
    {
        UIManager.Instance.PopPanel();
        GameControl.instance.GameBegin();

    }

    /// <summary>
    /// 皮肤界面的看广告按钮
    /// </summary>
    public void Button_WatchAd()
    {
        if (User.instance.skinOnSwitch.thisSkin.moneyNeed > 0)
        {
            User.instance.skinOnSwitch.PayForSkin();
            return;
        }

        User.instance.skinBool = true;
        /*********广告位**********/
        GoogleAdMobController.instance.ShowRewardAd();
    }



}
